import os
import numpy as np

STATIC_DATASET_PATH = r'../../../../../../large_data/_very_large/VOCtrainval_11-May-2012/VOCdevkit/VOC2012'
AT_LEAST_HOW_MANY = 10
dir_labels = os.path.join(STATIC_DATASET_PATH, 'labels')

result_arr = []
print('Start to seek ...')
file_names = os.listdir(dir_labels)
N_FILES = len(file_names)
N_GROUP = int(np.ceil(N_FILES / 20))
for i, file_name in enumerate(file_names):
    file_path = os.path.join(dir_labels, file_name)
    with open(file_path, 'r') as f:
        lines = f.readlines()
    cnt = 0
    for line in lines:
        line = line.strip()
        if len(line) > 0:
            cnt += 1
    if cnt >= AT_LEAST_HOW_MANY:
        result_arr.append([cnt, file_name])
    if i % N_GROUP == 0 or i == N_FILES - 1:
        print(f'Checked {i + 1} files.')

result_arr = sorted(result_arr, key=lambda x: x[0])
print(result_arr)
